﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace MyImage
{
    public partial class ShowDataCopy : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Image imgImage;
        private int THUMBNAIL_SIZE = 45;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                DataSet listImage = DataAcess.GetAllImage(true);
                dlImages.DataSource = listImage;
                dlImages.DataBind();
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

        }

        protected void dlImages_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void dlImages_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            System.Web.UI.WebControls.Image img = null;

            // make sure this is an item in the data list (not header etc.)
            if ((e.Item.ItemType == ListItemType.Item) ||
                (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                // get a reference to the image used for the bar in the row
                img = (System.Web.UI.WebControls.Image)
                    (e.Item.FindControl("Image1"));

                //get the img_pk from DataRow being bound
                int img_pk = Convert.ToInt16(
                    ((DataRowView)e.Item.DataItem).Row.ItemArray[0].ToString());

                ParseImageCopy.THUMBNAIL_SIZE = this.THUMBNAIL_SIZE;
                ParseImageCopy.USE_SIZE_FOR_HEIGHT = false;
                // set the source to the page that generates the thumbnail image
                img.ImageUrl = ParseImageCopy.PAGE_NAME + "?" + ParseImageCopy.IMAGE_ID + "=" + img_pk;
            }
        }
    }
}
